package pro.shushi.pamirs.ce.hr.core.excel;

import org.springframework.stereotype.Component;
import pro.shushi.pamirs.file.api.context.ExcelDefinitionContext;
import pro.shushi.pamirs.file.api.enmu.ExcelTemplateTypeEnum;
import pro.shushi.pamirs.file.api.extpoint.ExcelExportFetchDataExtPoint;
import pro.shushi.pamirs.file.api.extpoint.impl.ExcelExportSameQueryPageTemplate;
import pro.shushi.pamirs.file.api.model.ExcelExportTask;
import pro.shushi.pamirs.file.api.model.ExcelWorkbookDefinition;
import pro.shushi.pamirs.file.api.util.ExcelHelper;
import pro.shushi.pamirs.file.api.util.ExcelTemplateInit;
import pro.shushi.pamirs.meta.annotation.ExtPoint;
import pro.shushi.pamirs.ce.hr.api.model.CustBusinessTrip;

import java.util.Collections;
import java.util.List;

@Component
public class CustBusinessTripExportTemplate extends ExcelExportSameQueryPageTemplate implements ExcelTemplateInit , ExcelExportFetchDataExtPoint {
    public static final String TEMPLATE_NAME ="出差申请导出";

    @Override
    public List<ExcelWorkbookDefinition> generator() {
        //可以返回多个模版，导出的时候页面上由用户选择导出模版
        return Collections.singletonList(
                ExcelHelper.fixedHeader(CustBusinessTrip.MODEL_MODEL,TEMPLATE_NAME)
                        .createBlock(TEMPLATE_NAME, CustBusinessTrip.MODEL_MODEL)
                        .setType(ExcelTemplateTypeEnum.EXPORT)
                        .addColumn("code","编码")
                        .addColumn("employName","出差员工姓名")
                        .addColumn("businessReason","出差事由")
                        .addColumn("transportation","交通方式")
                        .addColumn("oneWayReturn","单程往返")
                        .build());
    }

    @Override
    @ExtPoint.Implement(expression = "context.model == \"" + CustBusinessTrip.MODEL_MODEL + "\" && context.name == \"" + TEMPLATE_NAME + "\"")
    public List<Object> fetchExportData(ExcelExportTask exportTask, ExcelDefinitionContext context) {
        //复用父类的权限控制等
        List<Object> result = super.fetchExportData(exportTask, context);
        //对petTalents做一些操作
        List<CustBusinessTrip> trips = (List<CustBusinessTrip>) result.get(0);
        for (CustBusinessTrip businessTrip : trips) {
            businessTrip.setBusinessReason(businessTrip.getBusinessReason() + ":被修改过");
        }
        return result;
    }

}
